package cn.edu.xjtu.android.emoji_warfare_android.game;

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Paint;
import cn.edu.xjtu.android.emoji_warfare_android.engine.shape.Circle;
import cn.edu.xjtu.android.emoji_warfare_android.engine.shape.Rectangle;

/**
 * 游戏设置
 * 
 * @author bill
 *
 */
public class Config {
    // 物理引擎扩展大小
    public static int margin = 400;
    // 虚拟屏幕宽度
    public static int screenWidth = 1080;
    // 虚拟屏幕高度
    public static int screenHeight = 1920;

    /**
     * 激光主要设置
     * 
     * @author bill
     *
     */
    public static class Laser {
        public static Rectangle outline;
        public static int imageCount = 4;
        public static Bitmap[] image;
        public static float width = 160;
        public static float height = 2000;
        public static float innerWidth = 120;

        public static void setImage(int index, Bitmap image) {
            Laser.image[index] = reshape(image, width, height);
        }

        static {
            image = new Bitmap[imageCount];
            outline = new Rectangle(-innerWidth / 2, -height, innerWidth / 2, 0);
        }
    }

    /**
     * 背景主要设置
     * 
     * @author bill
     *
     */
    public static class Back {
        public static Bitmap background;

        public static void setBackground(Bitmap b) {
            Back.background = reshape(b, screenWidth, screenHeight);
        }
    }

    /**
     * 盾牌主要设置
     * 
     * @author bill
     *
     */
    public static class Sheild {
        public static float len = 200;
        public static int lightImageCount = 90;
        public static Rectangle outline;
        public static Bitmap[] lightImage;
        public static Bitmap sheildBase;

        public static void setLightImage(int index, Bitmap image) {
            Sheild.lightImage[index] = reshape(image, len, len);
        }

        public static void setBaseImage(Bitmap image) {
            Sheild.sheildBase = reshape(image, len, len);
        }

        static {
            lightImage = new Bitmap[lightImageCount];
            outline = new Rectangle(-len / 2.0f, -len / 2.0f, len / 2.0f, len / 2.0f);
        }
    }

    /**
     * 掉落物品主要设置
     * 
     * @author bill
     *
     */
    public static class Item {
        public static float len = 120;
        public static float speed = 8;
        public static int imageCount = 5;
        public static Rectangle outline;
        public static Circle sheildOutline;
        public static Bitmap[] image;

        public static void setImage(int index, Bitmap image) {
            Item.image[index] = reshape(image, len, len);
        }

        static {
            image = new Bitmap[imageCount];
            outline = new Rectangle(-len / 2.0f, -len / 2.0f, len / 2.0f, len / 2.0f);
            sheildOutline = new Circle(len / 2.0f);
        }
    }

    /**
     * 子弹主要设置
     * 
     * @author bill
     *
     */
    public static class Bullet {
        public static float radius = 15;
        public static float speed = 20;
        public static Circle ouline;
        public final static int imageCount = 2;
        public final static Bitmap[] image;

        public static void setImage(int index, Bitmap image) {
            Bullet.image[index] = reshape(image, 2.0f * radius, 2.0f * radius);
        }

        static {
            // 初始化子弹轮廓
            ouline = new Circle(radius);
            image = new Bitmap[imageCount];
        }
    }

    /**
     * 所有的角色相关设置，包括玩家、敌人、Boss
     * 
     * @author bill
     *
     */
    public static class Hero {
        public final static float radius = 75;
        public final static int imageCount = 4;
        public final static Bitmap[] image;
        public final static int bossCount = 6;
        public final static Bitmap[] bosses;
        public final static float bossWidth = 450;
        public final static float bossHeight = 300;
        public final static Circle outline;
        public final static Circle playerOutline;

        public static void setImage(int index, Bitmap image) {
            Hero.image[index] = reshape(image, 2.0f * radius, 2.0f * radius);
        }

        public static void setBossImage(int index, Bitmap image) {
            Hero.bosses[index] = reshape(image, bossWidth, bossHeight);
        }

        static {
            // 初始化image数组
            image = new Bitmap[imageCount];
            bosses = new Bitmap[bossCount];
            // 初始化Hero轮廓
            outline = new Circle(radius);
            playerOutline = new Circle(radius / 2);

        }
    }

    /**
     * Common<br>
     * 通用<br>
     * 包括全局通用的图像绘制画笔等
     * 
     * @author bill
     *
     */
    public static class Common {
        public final static Paint bitmapPaint;
        static {
            // 初始化图像绘制画笔
            bitmapPaint = new Paint();
            bitmapPaint.setAntiAlias(true);
            bitmapPaint.setFilterBitmap(true);
            bitmapPaint.setDither(true);
        }
    }

    /**
     * 图像缩放
     * 
     * @param b
     *            需要缩放的位图
     * @param width
     *            目标宽度
     * @param height
     *            目标高度
     * @return 缩放后的图像
     */
    public static Bitmap reshape(Bitmap b, float width, float height) {
        Matrix matrix = new Matrix();
        matrix.postScale(width / b.getWidth(), height / b.getHeight());
        return Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
    }
}
